<?php


namespace App\Http\Controllers\Index;


use App\Http\Controllers\Controller;
use App\Model\Order;
use Illuminate\Http\Request;

class OrderController extends Controller
{
   public function add(Request $request){
       $data = $request->post();
       $order = new Order;
       $order->product_id = $data['product_id'];
       $order->user_id = $data['user_id'];
       $order->email = $data['email'];
       $order->wx = $data['wx'];
       if ($order->save()){
           return JsonResponse(200,true,'下单成功！');
       }else{
           return JsonResponse(4003,false,'下单失败，请稍后重试！',$order);
       }
   }

   public function order_list(Request $request){
       $data = $request->post();
       $list = Order::with('product')->where('user_id', $data['user_id'])->orderBy('id','DESC')->paginate(10,'*',2,$data['page']);
       return JsonResponse(200,true,'获取成功！',$list);
   }
}
